package com.mf.controller;


import com.mf.groups.GroupsAddInterface;
import com.mf.groups.GroupsUpdateInterface;
import com.mf.result.Result;
import com.mf.utils.UtilConverter;
import com.mf.entity.req.publicReq.ReqPublicIds;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

    
import com.mf.entity.dto.DtoSchedule;
import com.mf.entity.req.ReqSchedule;
import com.mf.service.ServiceSchedule;
import com.mf.entity.req.search.SearchReqSchedule;

import java.util.List;

/**
 * 排程
 * 
 */
@RestController
@RequestMapping("schedule")
@Tag(name = "排程")
public class ControllerSchedule {
    @Resource
    private ServiceSchedule serviceschedule;

    @Operation(summary = "分页列表查询")
    @PostMapping("/page")
    public Result<Page<DtoSchedule>> findPage(@RequestBody SearchReqSchedule searchReqSchedule) {
        return Result.success(serviceschedule.findPageByParams(searchReqSchedule));
    }

    @Operation(summary = "列表查询")
    @PostMapping("/list")
    public Result<List<DtoSchedule>> list(@RequestBody SearchReqSchedule searchReqSchedule) {
        return Result.success(serviceschedule.findListByParams(searchReqSchedule));
    }

    @Operation(summary = "保存")
    @PostMapping("/save")
    public Result<Void> save(@Validated(GroupsAddInterface.class) @RequestBody ReqSchedule reqSchedule) {
        serviceschedule.save(UtilConverter.convert(reqSchedule, DtoSchedule.class));
        return Result.success();
    }

    @Operation(summary = "修改")
    @PostMapping("/update")
    public Result<Void> update(@Validated(GroupsUpdateInterface.class) @RequestBody ReqSchedule reqSchedule) {
        serviceschedule.updateById(UtilConverter.convert(reqSchedule, DtoSchedule.class));
        return Result.success();
    }

    @Operation(summary = "删除")
    @PostMapping("/delete")
    public Result<Void> delete(@RequestBody ReqPublicIds<Integer> reqPublicIds) {
        serviceschedule.removeByIds(reqPublicIds.getIds());
        return Result.success();
    }

}
